home *** CD-ROM | disk | FTP | other *** search
/ ...taking it to the Macs! / ...taking it to the Macs!.iso / Extras / ActiveX Mac SDK / ActiveX SDK / Sample Controls / PowerPlant View / Directory Table ƒ / CDirectoryTable.cp next >
Encoding:
Text File  |  1996-11-27  |  9.5 KB  |  409 lines  |  [TEXT/CWIE]

  1. // ---------------------------------------------------------------------------
  2. //     CDirectoryTable.cp
  3. //     written by Rick Eames
  4. //     (c) 1996 Rick Eames.  All Rights Reserved.
  5. //    
  6. //    If I were really smart, I'd turn this into something abstract and allow
  7. //    overriding of key methods.  But I'm not that smart.  ;-)
  8. //
  9. // ---------------------------------------------------------------------------
  10.  
  11. #include "CDirectoryTable.h"
  12.  
  13. #include <LTableMonoGeometry.h>
  14. #include <LTableMultiGeometry.h>
  15. #include <LTableSingleSelector.h>
  16. #include <LTableMultiSelector.h>
  17. #include <LTableArrayStorage.h>
  18. #include <UAttachments.h>
  19. #include <UCollapsableTree.h>
  20. #include <UDrawingUtils.h>
  21. #include <UTextTraits.h>
  22.  
  23.  
  24. // ---------------------------------------------------------------------------
  25. // ---------------------------------------------------------------------------
  26.  
  27. const long        size_NameWidth         = 200;
  28. const long        size_UnreadWidth     = 50;
  29. const long        size_TotalWidth     = 50;
  30. const long        size_CellHeight     = 20;
  31. const long        kTextIndent         = 22;
  32. const long        kTextBottom            = 2;
  33. const ResIDT    icon_Folder            = 15000;
  34. const ResIDT    icon_Mail            = 15001;
  35. const ResIDT    icon_NewMail        = 15002;
  36.  
  37. // ---------------------------------------------------------------------------
  38. // ---------------------------------------------------------------------------
  39.  
  40. CDirectoryTable*
  41. CDirectoryTable::CreateFromStream(
  42.     LStream        *inStream)
  43. {
  44.     return (new CDirectoryTable(inStream));
  45. }
  46.  
  47. // ---------------------------------------------------------------------------
  48. // ---------------------------------------------------------------------------
  49.  
  50. CDirectoryTable::CDirectoryTable(
  51.     LStream        *inStream)
  52.         : LHierarchyTable(inStream)
  53. {
  54.     mTableGeometry = new LTableMultiGeometry(this, size_TotalWidth, size_CellHeight);
  55.     mTableSelector = new LTableMultiSelector(this);
  56.     mTableStorage = new LTableArrayStorage(this, sizeof(FSSpec));
  57.     
  58.     InsertCols(1, 0, nil, nil, false);
  59.     mTableGeometry->SetColWidth(size_NameWidth, 1, 1);
  60. //    mTableGeometry->SetColWidth(size_UnreadWidth, 2, 2);
  61. //    mTableGeometry->SetColWidth(size_TotalWidth, 3, 3);
  62.     
  63.     mCurrentRow = 0;
  64.     
  65.     mLastDragCell.row = mLastDragCell.col =-1;
  66.     
  67.     LEraseAttachment*    theAttachment;
  68.     theAttachment = new LEraseAttachment();
  69.     if (theAttachment)
  70.         AddAttachment(theAttachment, nil, true);
  71. }
  72.  
  73. #pragma mark -
  74.  
  75. // ---------------------------------------------------------------------------
  76. // ---------------------------------------------------------------------------
  77.  
  78. void
  79. CDirectoryTable::AddFile(
  80.     FSSpec        &inFile,
  81.     Int32        inParentRow,
  82.     Int32        /* inRow */,
  83.     Int32        inSiblingRow)
  84. {
  85.     if (inParentRow == 0)
  86.     {
  87.          InsertSiblingRows(1, inSiblingRow,&inFile, sizeof(FSSpec), false, true);
  88.     }
  89.     else
  90.     {
  91.         InsertChildRows(1, inParentRow, &inFile, sizeof(FSSpec), false, true);
  92.     }
  93.     
  94.     Refresh();
  95. }
  96.  
  97. // ---------------------------------------------------------------------------
  98. // ---------------------------------------------------------------------------
  99.  
  100. void
  101. CDirectoryTable::AddFolder(
  102.     FSSpec        &inFolder,
  103.     Int32        inParentRow,
  104.     Int32        /* inRow */,
  105.     Int32        inSiblingRow)
  106. {
  107.     if (inParentRow == 0)
  108.     {
  109.         InsertSiblingRows(1, inSiblingRow,&inFolder, sizeof(FSSpec), true, true);
  110.     }
  111.     else
  112.     {
  113.         InsertChildRows(1, inParentRow, &inFolder, sizeof(FSSpec), true, true);
  114.     }
  115.     
  116.     Refresh();
  117. }
  118.  
  119. // ---------------------------------------------------------------------------
  120. // ---------------------------------------------------------------------------
  121.  
  122. void
  123. CDirectoryTable::BuildList(
  124.     FSSpec        &inDirectory,
  125.     Int32        parentRow)
  126. {
  127.     CInfoPBRec    cipbr;
  128.     HFileInfo    *fpb = (HFileInfo*) &cipbr;
  129.     DirInfo        *dpb = (DirInfo*) &cipbr;
  130.     short        rc, index;
  131.     FSSpec        foundSpec;
  132.     Int32        dirID;
  133.     Int32        lastSiblingRow = 0;
  134.     
  135.     dirID = GetDirectoryID(inDirectory);
  136.     
  137.     fpb->ioVRefNum = inDirectory.vRefNum;
  138.     fpb->ioNamePtr = foundSpec.name;
  139.  
  140.     foundSpec.vRefNum = inDirectory.vRefNum;
  141.     foundSpec.parID = dirID;
  142.     
  143.     for (index = 1; true; index++)
  144.     {
  145.         fpb->ioDirID = dirID;
  146.         fpb->ioFDirIndex = index;
  147.         
  148.         rc = PBGetCatInfoSync(&cipbr);
  149.         if (rc) break;
  150.         
  151.         mCurrentRow++;    // this should be the wide open index
  152.         
  153.         if (fpb->ioFlAttrib & 16)
  154.         {
  155.             AddFolder(foundSpec, parentRow, mCurrentRow, lastSiblingRow);
  156.             lastSiblingRow = mCurrentRow;
  157.             BuildList(foundSpec, mCurrentRow);
  158.         }
  159.         else
  160.         {
  161. //            if (fpb->ioFlFndrInfo.fdType == 'MBOX')
  162. //            {
  163.                 AddFile(foundSpec, parentRow, mCurrentRow, lastSiblingRow);
  164.                 lastSiblingRow = mCurrentRow;
  165. //            }
  166.         }
  167.     }
  168. }
  169.  
  170. // ---------------------------------------------------------------------------
  171. // ---------------------------------------------------------------------------
  172.  
  173. Int32
  174. CDirectoryTable::GetDirectoryID(
  175.     FSSpec    &inDirectory)
  176. {
  177.     DirInfo        pb;
  178.     
  179.     pb.ioCompletion = nil;
  180.     pb.ioNamePtr = inDirectory.name;
  181.     pb.ioVRefNum = inDirectory.vRefNum;
  182.     pb.ioDrDirID = inDirectory.parID;
  183.     pb.ioFDirIndex = 0;
  184.     
  185.     Int16 err = ::PBGetCatInfoSync((CInfoPBRec*)&pb);
  186.     
  187.     return pb.ioDrDirID;
  188. }
  189.  
  190. #pragma mark -
  191.  
  192. // ---------------------------------------------------------------------------
  193. // ---------------------------------------------------------------------------
  194.  
  195. void            
  196. CDirectoryTable::DrawCell(
  197.     const STableCell    &inCell, 
  198.     const Rect            &inLocalRect)
  199. {
  200.     TableIndexT        woRow             = mCollapsableTree->GetWideOpenIndex(inCell.row);
  201.     Uint32            nestingLevel     = mCollapsableTree->GetNestingLevel(woRow);
  202.     STableCell        actualCell;
  203.     
  204.     actualCell = inCell;
  205.     actualCell.row = woRow;
  206.  
  207.     // get the data
  208.     FSSpec    theFile;
  209.     Uint32    theFileSize = sizeof(FSSpec);
  210.     
  211.     GetCellData(actualCell, &theFile, theFileSize);
  212.     
  213.     if (mCollapsableTree->IsCollapsable(woRow))
  214.     {
  215.         switch (inCell.col)
  216.         {
  217.             case 1:
  218.                 DrawDropFlag(inCell, woRow);
  219.                 UTextTraits::SetPortTextTraits(200);
  220.                 
  221.                 Rect    r;
  222.                 r = inLocalRect;
  223.                 r.left += (kTextIndent * (nestingLevel+1));
  224.                 r.right = r.left + 16;
  225.                 r.bottom = r.top + 16;
  226.                 
  227.                 ::PlotIconID(&r, atNone, ttNone, icon_Folder);
  228.                 
  229.                 r.top += 4;
  230.                 r.bottom += 4;
  231.                 r.left = r.right + 5;
  232.                 r.right = inLocalRect.right;
  233.                 
  234.                 UTextDrawing::DrawWithJustification((char*)&theFile.name[1], theFile.name[0], r, teJustLeft);
  235.                 break;
  236.                 
  237.             case 2:
  238.             {
  239.                 UTextTraits::SetPortTextTraits(200);
  240.                 Rect r = inLocalRect;
  241.                 r.top += 4;
  242.                 UTextDrawing::DrawWithJustification("-", 1, r, teJustCenter);
  243.                 break;
  244.             }
  245.             
  246.             case 3:
  247.             {
  248.                 UTextTraits::SetPortTextTraits(200);
  249.                 Rect r = inLocalRect;
  250.                 r.top += 4;
  251.                 UTextDrawing::DrawWithJustification("-", 1, r, teJustCenter);
  252.                 break;
  253.             }
  254.         }
  255.     }
  256.     else
  257.     {
  258.         UTextTraits::SetPortTextTraits(201);
  259.         
  260.         switch (inCell.col)
  261.         {
  262.             case 1:
  263.             {
  264.                 Rect    r;
  265.                 r = inLocalRect;
  266.                 r.left += (kTextIndent * (nestingLevel+1));
  267.                 r.right = r.left + 16;
  268.                 r.bottom = r.top + 16;
  269.                 
  270.                 ::PlotIconID(&r, atNone, ttNone, icon_Mail);
  271.                 
  272.                 r.left = r.right + 5;
  273.                 r.right = inLocalRect.right;
  274.                 r.top += 4;
  275.                 r.bottom += 4;
  276.                 
  277.                 UTextDrawing::DrawWithJustification((char*)&theFile.name[1], theFile.name[0], r, teJustLeft);
  278.                 
  279.                 break;
  280.             }
  281.             
  282.             case 2:
  283.             {
  284.                 Rect r = inLocalRect;
  285.                 r.top += 4;
  286.                 UTextDrawing::DrawWithJustification("123", 3, r, teJustCenter);
  287.                 break;
  288.             }
  289.             
  290.             case 3:
  291.             {
  292.                 Rect r = inLocalRect;
  293.                 r.top += 4;
  294.                 UTextDrawing::DrawWithJustification("500", 3, r, teJustCenter);
  295.                 break;
  296.             }
  297.         }
  298.     }
  299. }
  300.  
  301. // ---------------------------------------------------------------------------
  302. // ---------------------------------------------------------------------------
  303.  
  304. void
  305. CDirectoryTable::ClickCell(
  306.     const STableCell&         inCell,
  307.     const SMouseDownEvent&    inMouseDown)
  308. {
  309. #pragma unused (inMouseDown)
  310.     if (sClickCount < 2)
  311.     {
  312.     //    if (::WaitMouseMoved(inMouseDown.macEvent.where))
  313.     //    {
  314.     //        CreateDragEvent(inCell, inMouseDown);
  315.     //    }
  316.     }
  317.     else
  318.     {
  319.         TableIndexT        woRow             = mCollapsableTree->GetWideOpenIndex(inCell.row);
  320.         Uint32            nestingLevel     = mCollapsableTree->GetNestingLevel(woRow);
  321.         STableCell        actualCell;
  322.     
  323.         actualCell = inCell;
  324.         actualCell.row = woRow;
  325.     
  326.         // get the data
  327.         FSSpec    theFile;
  328.         Uint32    theFileSize = sizeof(FSSpec);
  329.         
  330.         GetCellData(actualCell, &theFile, theFileSize);
  331.         
  332.         BroadcastMessage('CLIK', &theFile);
  333.     }
  334. }
  335.  
  336. #pragma mark -
  337.  
  338. // ---------------------------------------------------------------------------
  339. //        • HiliteCellActively
  340. // ---------------------------------------------------------------------------
  341. //    Draw or undraw active hiliting for a Cell
  342.  
  343. void
  344. CDirectoryTable::HiliteCellActively(
  345.     const STableCell    &inCell,
  346.     Boolean                inHilite)
  347. {
  348. #if 0    
  349.     Rect        cellFrame;
  350.     STableCell    firstCell = inCell;
  351.     
  352.     TableIndexT        woRow = mCollapsableTree->GetWideOpenIndex(inCell.row);
  353.     
  354.     firstCell.col = 1;
  355.     
  356.     if (mCollapsableTree->IsCollapsable(woRow)) return;
  357.     
  358.     if (GetLocalCellRect(firstCell, cellFrame) && FocusExposed()) 
  359.     {
  360.         UDrawingUtils::SetHiliteModeOn();
  361.         ::InvertRect(&cellFrame);
  362.     }
  363. #else
  364. #pragma unused (inCell, inHilite)
  365. #endif
  366. }
  367.  
  368. // ---------------------------------------------------------------------------
  369. // ---------------------------------------------------------------------------
  370.  
  371. void
  372. CDirectoryTable::HiliteCellInactively(
  373.     const STableCell    &inCell,
  374.     Boolean                inHilite)
  375. {
  376. #if 0
  377. #pragma unused (inHilite)
  378.  
  379.     Rect    cellFrame;
  380.     
  381.     TableIndexT woRow = mCollapsableTree->GetWideOpenIndex(inCell.row);
  382.     
  383.     if (mCollapsableTree->IsCollapsable(woRow)) return;
  384.     
  385.     if (GetLocalCellRect(inCell, cellFrame) && FocusExposed()) 
  386.     {
  387.         UDrawingUtils::SetHiliteModeOn();
  388.         ::PenNormal();
  389.         ::PenMode(srcXor);
  390.         ::FrameRect(&cellFrame);
  391.     }
  392. #else
  393. #pragma unused (inCell, inHilite)
  394. #endif
  395. }
  396.  
  397. // ---------------------------------------------------------------------------
  398. // ---------------------------------------------------------------------------
  399.  
  400. void
  401. CDirectoryTable::HiliteSelection(
  402.     Boolean        isActively,
  403.     Boolean        inHilite)
  404. {
  405. #pragma unused (isActively, inHilite)
  406.     // do nothing
  407. }
  408.  
  409.